package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.SingleResponse;

import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.dto.base.Ids;
import com.authine.cloudpivot.ext.dto.kingDee.request.KingDeeBasicRequest;
import com.authine.cloudpivot.ext.dto.pm.RecordingVoucherDTO;
import com.authine.cloudpivot.ext.dto.pm.RecordingVoucherDTO2;
import com.authine.cloudpivot.ext.dto.query.RecordingVoucherQuery;
import com.authine.cloudpivot.ext.dto.voucher.KingDeeBasicStats;
import com.authine.cloudpivot.ext.dto.voucher.Voucher;
import com.authine.cloudpivot.ext.kingdee.work.OtherWork;
import com.authine.cloudpivot.ext.service.voucher.impl.RecordingVoucherPmServiceImpl;
import com.authine.hermes.app.launcher.service.ApplicationService;
import com.authine.mvp.app.launcher.dto.bo.response.BOList;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.List;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @Author: liwei
 * @DateTime: 2021/7/24
 * @Description: TODO 此类需要放到财务模块中
 */
@Path("RecordingVoucherPmController")
@Slf4j
public class RecordingVoucherPmController extends ApplicationService {


    private RecordingVoucherPmServiceImpl recordingVoucherPmService = new RecordingVoucherPmServiceImpl();

    @Path("delRecordingVoucher")
    @POST
    @Operation(summary = "批量删除凭证", tags = CUSTOM_SERVICE)
    public SingleResponse delRecordingVoucher(@Parameter Ids ids) {
        Assert.notNull(ids.getIds(),"delRecordingVoucher ids 集合不能为空！！！");
        return recordingVoucherPmService.deleteRecordingVoucherByIds(ids.getIds());
    }


    @Path("saveRecordingAndInvoice")
    @POST
    @Operation(summary = "生成凭证", tags = CUSTOM_SERVICE)
    public SingleResponse<String> saveRecordingAndInvoice(@Parameter List<RecordingVoucherDTO> recordingVoucherDTOList) {

        String result = recordingVoucherPmService.saveRecordingAndInvoice(recordingVoucherDTOList);

        return SingleResponse.buildSuccess();

    }


    @Path("saveServiceFeeInvoice")
    @POST
    @Operation(summary = "服务费蓝票", tags = CUSTOM_SERVICE)
    public SingleResponse<String> saveServiceFeeInvoice(@Parameter List<RecordingVoucherDTO2> recordingVoucherDTO2s) {

        String result = recordingVoucherPmService.saveServiceFeeInvoice(recordingVoucherDTO2s);

        return SingleResponse.buildSuccess();

    }

    @Path("saveRedServiceFeeInvoice")
    @POST
    @Operation(summary = "服务费红票", tags = CUSTOM_SERVICE)
    public SingleResponse<String> saveRedServiceFeeInvoice(@Parameter List<RecordingVoucherDTO2> recordingVoucherDTO2s) {

        String result = recordingVoucherPmService.saveRedServiceFeeInvoice(recordingVoucherDTO2s);

        return SingleResponse.buildSuccess();

    }

    //pushVoucher
    @Path("pushVoucher")
    @POST
    @Operation(summary = "生成凭证-K3", tags = CUSTOM_SERVICE)
    public SingleResponse<Integer> pushVoucher(@Parameter List<Voucher> voucher) {

        Integer result = recordingVoucherPmService.pushVoucher(voucher);

        return SingleResponse.buildSuccess();

    }

    @Path("listKingDeeBasicStats")
    @POST
    @Operation(summary = "金蝶组织信息/根据组织名称查询金蝶编码", tags = CUSTOM_SERVICE)
    public SingleResponse<List<KingDeeBasicStats>> listKingDeeBasicStats(@Parameter KingDeeBasicRequest request) {

        return recordingVoucherPmService.listByCompanyName(request);
    }

    @Path("saveKingDeeBasicStats")
    @POST
    @Operation(summary = "金蝶组织信息/新建（凭证页面弹框用）", tags = CUSTOM_SERVICE)
    public SingleResponse<List<String>> saveKingDeeBasicStats(@Parameter List<KingDeeBasicStats> params) {

        return recordingVoucherPmService.saveKingDeeBasicStats(params);
    }

    @Path("saveDimension")
    @POST
    @Operation(summary = "维度管理/新建", tags = CUSTOM_SERVICE)
    public SingleResponse<String> saveDimension(@Parameter KingDeeBasicStats param) {

        return recordingVoucherPmService.saveDimension(param);
    }

    @Path("updateKingDeeBasicStats")
    @POST
    @Operation(summary = "金蝶组织信息/更新", tags = CUSTOM_SERVICE)
    public SingleResponse updateKingDeeBasicStats(@Parameter KingDeeBasicStats param) {

        return recordingVoucherPmService.updateKingDeeBasicStats(param);
    }

    @Path("listRecordingVoucher")
    @POST
    @Operation(summary = "凭证记录/列表", tags = CUSTOM_SERVICE)
    public SingleResponse<BOList> listRecordingVoucher(@Parameter RecordingVoucherQuery query) {

        return recordingVoucherPmService.listRecordingVoucher(query);
    }

}
